<?php


namespace app\shop\model;


use think\Model;

class GoodsAttributeModel extends Model
{
    protected $table = 'dp_goods_attribute';
    protected $pk = 'attr_id';
    protected $field = true;

    public function type()
    {
        return $this->hasOne('GoodsTypeModel','id','type_id')->bind(['type_name'=>'name']);
    }

    public static function getList($type_id=0)
    {
        if($type_id==0){
            return self::with('type')->paginate(10);
        }else{
            return self::with('type')->where('type_id',$type_id)->paginate(10);
        }
    }

    public static function getRes($type_id=0)
    {
        return self::where('type_id',$type_id)->select();

    }

    public static function saveAttr($data, $id=0)
    {
        if($id==0){
            return self::create($data);
        }else{
            return self::where('attr_id',$id)->update($data);
        }

    }



}